package com.kcth.sylyg08.rest;

import com.kcht.adp.common.log.Logger;
import com.kcht.adp.common.utils.BeanUtils;
import com.kcht.sylyg08.service.IGetMaterialInfoFromMes;
import com.kcht.sylyg08.service.IGetProductInfoFromMes;
import com.kcth.sylyg08.entity.Material;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import java.util.Optional;

/**
 * @Package: com.kcth.sylyg08.rest
 * @Description: 通过MES系统，获取物料信息
 * @Author: lenovo
 * @CreateDate: 2019/5/20 13:00
 */
@Path("/getMaterialInfo")
@RequestScoped
@Transactional(value= Transactional.TxType.NOT_SUPPORTED,rollbackOn=Exception.class)
public class GetMaterialInfo {
    @Context
    private HttpServletRequest request;
    @Inject
    private Logger logger;
    @Inject
    IGetMaterialInfoFromMes getMaterialInfoFromMes;

    @POST
    @Produces("application/json")
    @Consumes("application/json")
    public Object getMaterialInfo(Material material) throws Exception {
        /** 请求上层应用 MES 系统获取物料信息 */
        String realIP = Optional.ofNullable(request.getHeader("X-Real-IP")).orElse(request.getRemoteAddr());
        logger.info(String.format("[%s]=>POST请求地址:%s/%s", realIP, "GetMaterialInfo", "getMaterialInfo"));
        logger.info(String.format("[%s]=>POST请求参数:%s", realIP, BeanUtils.ignoreBigProperty(material)));
        Material ret = getMaterialInfoFromMes.getMaterialInfoFromMes(material);
        logger.info("return =>" + BeanUtils.ignoreBigProperty(ret));
        return ret;

        /** 生成标签的 EPC 码，在数据库中记录对应关系 */


        /** 返回 产品唯一编码， EPC 码 等相关信息 */
    }
}
